package jiezi.game 
{
	import flash.display.Bitmap;
	/**
	 * ...
	 * @author ...
	 */

	public class jzTextureManager 
	{
		private static var mInstance:jzTextureManager = null;
		
		private var mFreeLoader:Array = new Array();
		private var mLoadedBitmaps:Object = new Object();
		
		public static function getSingleton():jzTextureManager 
		{
			if( mInstance == null )
			{
				mInstance = new jzTextureManager();
			}
			return mInstance;
		}

		public function jzTextureManager()
		{
		}
		
		public function getTexture(name:String):Bitmap
		{
			if ( name in mLoadedBitmaps ) {
				return mLoadedBitmaps[name];
			}
			if ( mFreeLoader.length == 0 ) {
				mFreeLoader.push(new jzTextureLoader)	
			}
			mFreeLoader.pop().load(name);
			return null;
		}
		
		public function addLoadedTexture(name:String, tex:*, loader:jzTextureLoader):void
		{
			mFreeLoader.push(loader);
			mLoadedBitmaps[name] = tex;
		}
		
	}

}